package cn.wolfcode.trip.app.interceptor;

import cn.wolfcode.trip.app.util.UserContext;
import cn.wolfcode.trip.base.domain.User;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor extends HandlerInterceptorAdapter {
   @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
       User user = UserContext.getCurrentUser();
       if(user==null){
           //利用重定向回到登录页面
           response.sendRedirect("/login.html");
              return false;
          }
        return true;
    }
}
